package logMonitor.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import logMonitor.domain.Message;
import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.Date;

/**
 * Created by lenovo on 2018/1/10.
 */
public class DataSourceUtil {
    private static Logger logger = Logger.getLogger(DataSourceUtil.class);
    private static DataSource dataSource;

    static {
        dataSource = new ComboPooledDataSource("logMonitor");
    }

    public static synchronized DataSource getDataSource() {
        if (dataSource == null) {
            dataSource = new ComboPooledDataSource();
        }
        return dataSource;
    }

    public static void main(String[] args) {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
//        String sql = "SELECT `id`,`name`,`keyword`,`isValid`,`appId` FROM `log_monitor`.`log_monitor_rule` WHERE isValid =1";
//        System.out.println(jdbcTemplate.query(sql, new BeanPropertyRowMapper<RuleField>(RuleField.class)));

        Message record = new Message();
        record.setSrc_ip("123123");
        record.setDst_ip("123123");
        String sql = "INSERT INTO `log_monitor`.`users`" +
                " (`name`,`mobilePhone`,`email`,`isValid`) " +
                "VALUES ( ?,?,?,?)";
        jdbcTemplate.update(sql, "sdfsd", "sdfsd","sdfsd","sdfsd");

    }
}
